using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using System;
using System.Collections;
using yW5Lib;

namespace yWriter6
{
	[StandardModule]
	internal sealed class modScenesPerChar
	{
		public static void ShowScenesPerChar(clsProject cProject)
		{
			//Discarded unreachable code: IL_016c, IL_0183, IL_018e, IL_019e, IL_020c, IL_020e, IL_0222, IL_0244
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				UpdateScenesPerChar(cProject);
				num2 = 3;
				string text = "";
				num2 = 4;
				int usedSceneCount = cProject.UsedSceneCount;
				num2 = 5;
				if (usedSceneCount == 0)
				{
					num2 = 6;
					clsShared.cLang.TransMsgBox("All scenes in this project have been marked unused");
				}
				else
				{
					num2 = 8;
					clsShared.cSubs.BusyMouse();
					num2 = 9;
					IEnumerator enumerator = cProject.Chars.GetEnumerator();
					while (enumerator.MoveNext())
					{
						clsCharacter clsCharacter = (clsCharacter)enumerator.Current;
						num2 = 10;
						string text2;
						if (clsCharacter.VPSceneCount == 0)
						{
							num2 = 11;
							text2 = "(0.00%)";
						}
						else
						{
							num2 = 13;
							text2 = Strings.Format((double)clsCharacter.VPSceneCount / (double)usedSceneCount, "(0.00%)");
						}
						num2 = 14;
						text = text + clsCharacter.Title + ": " + Conversions.ToString(clsCharacter.VPSceneCount) + " " + text2 + "\r\n";
						num2 = 15;
					}
					num2 = 16;
					if (enumerator is IDisposable)
					{
						(enumerator as IDisposable).Dispose();
					}
					num2 = 17;
					if (Operators.CompareString(text, "", TextCompare: false) == 0)
					{
						num2 = 18;
						clsShared.cLang.TransMsgBox("No characters in project");
					}
					else
					{
						num2 = 20;
						clsShared.cLang.TransMsgBox("@1@(Does not include unused scenes or scenes within unused chapters)", MsgBoxStyle.OkOnly, "", text + "\r\n");
					}
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0242: Could not find block for branch target IL_020e*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}

		public static void UpdateScenesPerChar(clsProject cProject)
		{
			//Discarded unreachable code: IL_0188, IL_019f, IL_01aa, IL_01ba, IL_023c, IL_023e, IL_0252, IL_0274
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				clsShared.cSubs.BusyMouse();
				num2 = 3;
				IEnumerator enumerator = cProject.Chars.GetEnumerator();
				while (enumerator.MoveNext())
				{
					clsCharacter clsCharacter = (clsCharacter)enumerator.Current;
					num2 = 4;
					clsCharacter.VPSceneCount = 0;
					num2 = 5;
					clsCharacter.VPSceneCountUnused = 0;
					num2 = 6;
					clsCharacter.SceneCount = 0;
					num2 = 7;
				}
				num2 = 8;
				if (enumerator is IDisposable)
				{
					(enumerator as IDisposable).Dispose();
				}
				num2 = 9;
				IEnumerator enumerator2 = cProject.Scenes.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					clsScene clsScene = (clsScene)enumerator2.Current;
					num2 = 10;
					bool flag = false;
					num2 = 11;
					if (!clsScene.Unused)
					{
						num2 = 12;
						if (!cProject.get_ChapterByID(clsScene.BelongsToChID).Unused)
						{
							num2 = 13;
							flag = true;
						}
					}
					num2 = 14;
					int viewPointID = clsScene.ViewPointID;
					num2 = 15;
					if (flag)
					{
						num2 = 16;
						cProject.get_CharByID(viewPointID).VPSceneCount++;
					}
					else
					{
						num2 = 18;
						cProject.get_CharByID(viewPointID).VPSceneCountUnused++;
					}
					num2 = 19;
					int charCount = clsScene.CharCount;
					for (int i = 2; i <= charCount; i++)
					{
						num2 = 20;
						int iD = ((clsSceneBase)clsScene).get_CharIDByIndex(i);
						num2 = 21;
						if (flag)
						{
							num2 = 22;
							cProject.get_CharByID(iD).SceneCount++;
						}
						num2 = 23;
					}
					num2 = 24;
				}
				num2 = 25;
				if (enumerator2 is IDisposable)
				{
					(enumerator2 as IDisposable).Dispose();
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_0272: Could not find block for branch target IL_023e*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}
	}
}
